package org.sample.springbootredis.web;

import java.util.List;

import org.sample.springbootredis.client.model.UserDTO;
import org.sample.springbootredis.service.LockUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
@RequestMapping("/user/lock")
public class UserLockController {

	@Autowired
	private LockUserService service;

	@GetMapping("/all")
	public List<UserDTO> findAll() {
		return service.findAllUsers();
	}

	@GetMapping("/{id}")
	public UserDTO findById(@PathVariable("id") Long id) {
		return service.findUserById(id);
	}

	@PostMapping
	public UserDTO create(@RequestBody UserDTO userDTO) {
		return service.createUser(userDTO);
	}

	@PutMapping("/{id}")
	public UserDTO updateById(@PathVariable("id") Long id, @RequestBody UserDTO userDTO) {
		userDTO.setId(id);
		return service.updateUserById(userDTO);
	}

	@DeleteMapping("/{id}")
	public void deleteById(@PathVariable("id") Long id) {
		service.deleteUserById(id);
	}

}
